<template>
  <div class="app-container">
    <div class="search-bar">
      <el-date-picker
        v-model="searchData.year"
        type="year"
        placeholder="请选择年度查询"
        value-format="yyyy"
      ></el-date-picker>
      <el-input v-model="searchData.dkmc" placeholder="请输入地块名称查询" />

      <el-input v-model="searchData.hhrxm" placeholder="请输入合伙人姓名查询" />

      <el-button
        v-waves
        type="primary"
        size="small"
        icon="el-icon-search"
        @click="searchBtnHandle"
        >查询</el-button
      >
      <el-button
        v-waves
        type="info"
        size="small"
        icon="el-icon-refresh"
        @click="resetTableList"
        >显示全部</el-button
      >
      <div style="float: right"></div>
    </div>
    <el-table
      ref="dataTable"
      :data="tableData"
      stripe
      border
      v-loading="isLoading"
    >
      <el-table-column
        type="selection"
        width="50"
        align="center"
        header-align="center"
      />
      <el-table-column label="种植年度" prop="jhnd" align="center" />
      <el-table-column label="地块名称" prop="dkmc" align="center" />
      <el-table-column label="种植计划" prop="jhmc" align="center" />
      <el-table-column label="种植面积(亩)" prop="dkmj" align="center" />
      <el-table-column label="农户姓名" prop="nhxm" align="center" />
      <el-table-column label="农户固定收益(元)" prop="nhgdsy" align="center" />
      <el-table-column label="地块收入(元)" prop="zsr" align="center" />
      <el-table-column label="合伙人" prop="hhrxm" align="center" />
      <el-table-column
        label="合伙人固定收益(元)"
        prop="hhrgdsy"
        align="center"
      />
      <el-table-column label="超额分红(元)" prop="cyfh" align="center" />
      <el-table-column label="操作" prop="sr" align="center">
        <template slot-scope="scope">
          <el-button type="text" size="mini" @click="openView(scope.row)"
            >打印</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      style="text-align: center; margin-top: 10px"
      layout="total,prev,pager,next,sizes,jumper"
      :page-size="pager.limit"
      :current-page="pager.page"
      :total="pager.totalCount"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
    <el-dialog
      title=""
      :visible.sync="dialogVisible"
      width="1000px"
      @close="dialogVisible = false"
    >
      <div id="printArea">
        <h2 class="text-center">合伙人收益报表</h2>
        <div style="padding: 0 30px">
          <el-descriptions title="地块基本情况">
            <el-descriptions-item label="地块名称">{{
              tableRow.dkmc
            }}</el-descriptions-item>
            <el-descriptions-item label="农户姓名">{{
              tableRow.nhxm
            }}</el-descriptions-item>
            <el-descriptions-item label="种植面积"
              >{{ tableRow.dkmj }}亩</el-descriptions-item
            >
            <el-descriptions-item label="种植年度">{{
              tableRow.jhnd
            }}</el-descriptions-item>
            <el-descriptions-item label="种植计划">{{
              tableRow.jhmc
            }}</el-descriptions-item>
            <el-descriptions-item label="种植作物">{{
              tableRow.zzzw
            }}</el-descriptions-item>
            <el-descriptions-item label="总产量">{{
              tableRow.zcl
            }}</el-descriptions-item>
            <el-descriptions-item label="总收入"
              >{{
                tableRow.zsr && tableRow.zsr.toFixed(2)
              }}元</el-descriptions-item
            >
          </el-descriptions>
          <p>
            <span class="des-title">农户固定收益：</span>
            {{ tableRow.nhgdsy && tableRow.nhgdsy.toFixed(2) }}元
          </p>
          <el-descriptions title="合伙人收益" :column="1">
            <el-descriptions-item label="合伙人">{{
              tableRow.hhrxm
            }}</el-descriptions-item>
            <el-descriptions-item label="固定收益"
              >{{
                tableRow.hhrgdsy && tableRow.hhrgdsy.toFixed(2)
              }}元</el-descriptions-item
            >
            <el-descriptions-item label="超额分红"
              >{{
                tableRow.cyfh && tableRow.cyfh.toFixed(2)
              }}元</el-descriptions-item
            >
          </el-descriptions>
          <!-- <p>
            <span class="des-title">核算人：</span>
            {{ tableRow.nhgdsy }}
          </p> -->
          <p>
            <span class="des-title">打印日期：</span>
            {{ timeFormat }}
          </p>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button v-waves type="primary" v-print="'#printArea'"
          >打印</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import moment from "moment";
import request from "@/utils/request";
import print from "vue-print-nb";
export default {
  directives: {
    print,
  },
  data() {
    return {
      searchData: {},
      tableData: [],
      yearList: [],
      pager: {
        page: 1,
        limit: 10,
        totalCount: 0,
      },
      isLoading: false,
      url: {
        list: "/jtnc/bigdata/listHhrjx",
      },
      tableRow: {},
      dialogVisible: false,
    };
  },
  created() {
    this.loadTableList();
  },
  computed: {
    timeFormat() {
      return moment().format("YYYY年MM月DD日");
    },
  },
  methods: {
    loadTableList() {
      this.isLoading = true;
      const params = { ...this.pager, ...this.searchData };
      request({
        url: this.url.list,
        method: "get",
        params,
      }).then((response) => {
        const { data } = response;
        this.pager.totalCount = data.total;
        this.tableData = data.records;
        this.isLoading = false;
      });
    },
    // 查询按钮
    searchBtnHandle() {
      this.pager.page = 1;
      this.loadTableList();
    },
    // 显示全部
    resetTableList() {
      this.pager.page = 1;
      this.searchData = {};
      this.timePickageValue = "";
      this.loadTableList();
    },
    openView(row) {
      this.dialogVisible = true;
      this.tableRow = row;
    },
    // 监听分页
    handleCurrentChange(page) {
      this.pager.page = page;
      this.loadTableList();
    },
    // 分页条数改变
    handleSizeChange(size) {
      this.pager.limit = size;
      this.loadTableList();
    },
    print() {},
  },
};
</script>

<style lang="scss" scoped>
.search-bar {
  margin-bottom: 10px;
  ::v-deep {
    .el-input,
    .el-select {
      width: 180px;
      margin-right: 10px;
      margin-bottom: 5px;
    }
  }
}
.des-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 20px;
  color: #303133;
}
</style>
